/******************************************************************************
 * 
 * @file bsp_ST7789_driver.h
 *
 * @author Emond
 *
 * @brief 
 * 
 * @version V1.0
 *
 * @note 1 tab == 4 spaces!
 *
 *****************************************************************************/

 #ifndef    _BSP_ST7789_DRIVER_H_
 #define    _BSP_ST7789_DRIVER_H_

//********************** Includes ************************//
#include "fonts.h"
#include <stdint.h>
//********************** Includes ************************//


//********************** Typdef **************************//

typedef struct spi_gpio_driver_interface_obj
{
    uint8_t (* pf_spi_transmist)(uint8_t * pdata,uint16_t datalength);
    uint8_t (* pf_spi_transmist_dma)(uint8_t * pdata,uint16_t datalength);
    uint8_t (* pf_spi_reset_pin)(uint8_t pinstatus);
    uint8_t (* pf_spi_cs_pin)(uint8_t pinstatus);
    uint8_t (* pf_spi_dc_pin)(uint8_t pinstatus);
} base_operat_driver_interface_t;

typedef struct st7789_driver_spi_interface_obj
{
    uint8_t (* pf_st7789_write_data)(void * const driver_instance, uint8_t * pdata, uint32_t datalength);
    uint8_t (* pf_st7789_write_simple_data)(void * const driver_instance,const uint8_t datasend);
    uint8_t (* pf_st7789_write_command)(void * const driver_instance,const uint8_t cmd, uint32_t datalength);
} st7789_spi_driver_interface_t;

typedef struct st7789_timebase_obj
{
    uint32_t (*pf_get_tick_count)(void);
    void (*pf_delay_no_os)(uint32_t time);
} st7789_timebase_interface_t;

typedef struct st7789_yield_interface_obj
{
    void (* pf_rtos_yield)(const uint32_t yield_cnt);
} st7789_yield_interface_t;

typedef struct bsp_st7789_driver_t
{
    base_operat_driver_interface_t * p_spi_basic_operation;
    st7789_spi_driver_interface_t * p_st7789_spi_instance;
    st7789_timebase_interface_t * p_st7789_timebase_instance;
    st7789_yield_interface_t * p_st7789_yield_instance;

    uint8_t (* pf_st7789_init)(void * const st7789_instance);
    uint8_t (* pf_set_direction)(void * const st7789_instance,uint8_t direction);
    uint8_t (* pf_fill_color)(void * const st7789_instance,uint16_t color);
    uint8_t (* pf_draw_pixel)(void * const st7789_instance,uint16_t color,uint16_t x,uint16_t y);
    uint8_t (* pf_fill)(void * const st7789_instance,uint16_t xSta,uint16_t yStr,uint16_t xEnd,uint16_t yEnd,uint16_t color);
    uint8_t (* pf_draw_pixel_4pixel)(void * const st7789_instance,uint16_t x,uint16_t y,uint16_t color);
    uint8_t (* pf_set_addr_window)(void * const st7789_instance,uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1);

    uint8_t (* pf_draw_line)(void * const st7789_instance,uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y2,uint16_t color);
    uint8_t (* pf_draw_rectangle)(void * const st7789_instance,uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
    uint8_t (* pf_draw_circle)(void * const st7789_instance,uint16_t x0, uint16_t y0, uint8_t r, uint16_t color);
    uint8_t (* pf_draw_image)(void * const st7789_instance,uint16_t x, uint16_t y, uint16_t w, uint16_t h, const uint16_t *data);
    uint8_t (* pf_draw_invert_colors)(void * const st7789_instance,uint8_t invert);

    uint8_t (* pf_write_char)(void * const st7789_instance,uint16_t x,uint16_t y,char ch,font_def_t font,uint16_t color,uint16_t bgcolor);
    uint8_t (* pf_write_string)(void * const st7789_instance,uint16_t x,uint16_t y,uint8_t * str,font_def_t font,uint16_t color,uint16_t bgcolor);

    uint8_t (* pf_filled_rectangle)(void * const st7789_instance,uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color);
    uint8_t (* pf_draw_triangle)(void * const st7789_instance,uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, uint16_t color);
    uint8_t (* pf_filled_triangle)(void * const st7789_instance,uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, uint16_t color);
    uint8_t (* pf_draw_filled_circle)(void * const st7789_instance,int16_t x0, int16_t y0, int16_t r, uint16_t color);

    uint8_t (* pf_tear_effect)(void * const st7789_instance,uint8_t tear);

    uint8_t (* pf_test_device)(void * const st7789_instance);
} bsp_st7789_driver_t;
//********************** Typdef **************************//


//********************** Defines *************************//
uint8_t st7789_instance_driver_link(bsp_st7789_driver_t *const st7789_driver_instance,
    base_operat_driver_interface_t *const st7789_basic_operation_instance,
    st7789_spi_driver_interface_t *const st7789_spi_instance,
    st7789_timebase_interface_t *const timebase_instance,
    st7789_yield_interface_t *const yield_instance);
//********************** Defines *************************//


#endif
